load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])

java_proto_library(
    name = "testing_api_java_proto",
    testonly = 1,
    deps = ["@tink_base//proto/testing:testing_api_proto"],
)

java_grpc_library(
    name = "testing_api_java_grpc",
    testonly = 1,
    srcs = ["@tink_base//proto/testing:testing_api_proto"],
    deps = [":testing_api_java_proto"],
)

java_library(
    name = "testing_services",
    testonly = 1,
    srcs = [
        "java/com/google/crypto/tink/testing/AeadServiceImpl.java",
        "java/com/google/crypto/tink/testing/DeterministicAeadServiceImpl.java",
        "java/com/google/crypto/tink/testing/HybridServiceImpl.java",
        "java/com/google/crypto/tink/testing/JwtServiceImpl.java",
        "java/com/google/crypto/tink/testing/KeysetServiceImpl.java",
        "java/com/google/crypto/tink/testing/MacServiceImpl.java",
        "java/com/google/crypto/tink/testing/MetadataServiceImpl.java",
        "java/com/google/crypto/tink/testing/PrfSetServiceImpl.java",
        "java/com/google/crypto/tink/testing/SignatureServiceImpl.java",
        "java/com/google/crypto/tink/testing/StreamingAeadServiceImpl.java",
    ],
    deps = [
        ":testing_api_java_grpc",
        ":testing_api_java_proto",
        "@com_google_protobuf//:protobuf_java",
        "@io_grpc_grpc_java//api",
        "@io_grpc_grpc_java//protobuf",
        "@io_grpc_grpc_java//stub",
        "@tink_java//proto:tink_java_proto",
        "@tink_java//src/main/java/com/google/crypto/tink:aead",
        "@tink_java//src/main/java/com/google/crypto/tink:binary_keyset_reader",
        "@tink_java//src/main/java/com/google/crypto/tink:binary_keyset_writer",
        "@tink_java//src/main/java/com/google/crypto/tink:cleartext_keyset_handle",
        "@tink_java//src/main/java/com/google/crypto/tink:deterministic_aead",
        "@tink_java//src/main/java/com/google/crypto/tink:hybrid_decrypt",
        "@tink_java//src/main/java/com/google/crypto/tink:hybrid_encrypt",
        "@tink_java//src/main/java/com/google/crypto/tink:json_keyset_reader",
        "@tink_java//src/main/java/com/google/crypto/tink:json_keyset_writer",
        "@tink_java//src/main/java/com/google/crypto/tink:key_template",
        "@tink_java//src/main/java/com/google/crypto/tink:key_templates",
        "@tink_java//src/main/java/com/google/crypto/tink:keyset_reader",
        "@tink_java//src/main/java/com/google/crypto/tink:keyset_writer",
        "@tink_java//src/main/java/com/google/crypto/tink:mac",
        "@tink_java//src/main/java/com/google/crypto/tink:public_key_sign",
        "@tink_java//src/main/java/com/google/crypto/tink:public_key_verify",
        "@tink_java//src/main/java/com/google/crypto/tink:registry_cluster",
        "@tink_java//src/main/java/com/google/crypto/tink:streaming_aead",
        "@tink_java//src/main/java/com/google/crypto/tink:version",
        "@tink_java//src/main/java/com/google/crypto/tink/internal:key_template_proto_converter",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwk_set_converter",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_invalid_exception",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_mac",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_mac_config",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_public_key_sign",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_public_key_verify",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_signature_config",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_validator",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:raw_jwt",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:verified_jwt",
        "@tink_java//src/main/java/com/google/crypto/tink/prf:prf_set",
        "@tink_java//src/main/java/com/google/crypto/tink/tinkkey:secret_key_access",
    ],
)

java_binary(
    name = "testing_server",
    testonly = 1,
    srcs = [
        "java/com/google/crypto/tink/testing/TestingServer.java",
    ],
    main_class = "com.google.crypto.tink.testing.TestingServer",
    runtime_deps = [
        "@io_grpc_grpc_java//netty",
    ],
    deps = [
        ":testing_services",
        "@io_grpc_grpc_java//api",
        "@maven//:org_conscrypt_conscrypt_openjdk_uber",
        "@tink_java//src/main/java/com/google/crypto/tink:kms_clients",
        "@tink_java//src/main/java/com/google/crypto/tink/aead:aead_config",
        "@tink_java//src/main/java/com/google/crypto/tink/daead:deterministic_aead_config",
        "@tink_java//src/main/java/com/google/crypto/tink/hybrid:hybrid_config",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_mac_config",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_signature_config",
        "@tink_java//src/main/java/com/google/crypto/tink/mac:mac_config",
        "@tink_java//src/main/java/com/google/crypto/tink/prf:prf_config",
        "@tink_java//src/main/java/com/google/crypto/tink/signature:signature_config",
        "@tink_java//src/main/java/com/google/crypto/tink/streamingaead:streaming_aead_config",
        "@tink_java//src/main/java/com/google/crypto/tink/testing:fake_kms_client",
    ],
)

java_test(
    name = "TestingServicesTest",
    size = "small",
    srcs = [
        "javatests/com/google/crypto/tink/testing/TestingServicesTest.java",
    ],
    deps = [
        ":testing_api_java_grpc",
        ":testing_api_java_proto",
        ":testing_services",
        "@com_google_protobuf//:protobuf_java",
        "@com_google_protobuf//:protobuf_java_util",
        "@io_grpc_grpc_java//api",
        "@io_grpc_grpc_java//core:inprocess",
        "@io_grpc_grpc_java//protobuf",
        "@io_grpc_grpc_java//stub",
        "@io_grpc_grpc_java//testing",
        "@maven//:com_google_truth_truth",
        "@maven//:junit_junit",
        "@tink_java//proto:tink_java_proto",
        "@tink_java//src/main/java/com/google/crypto/tink:binary_keyset_reader",
        "@tink_java//src/main/java/com/google/crypto/tink:key_template",
        "@tink_java//src/main/java/com/google/crypto/tink:key_templates",
        "@tink_java//src/main/java/com/google/crypto/tink/config:tink_config",
        "@tink_java//src/main/java/com/google/crypto/tink/daead:aes_siv_key_manager",
        "@tink_java//src/main/java/com/google/crypto/tink/internal:key_template_proto_converter",
        "@tink_java//src/main/java/com/google/crypto/tink/mac:hmac_key_manager",
        "@tink_java//src/main/java/com/google/crypto/tink/prf:hmac_prf_key_manager",
        "@tink_java//src/main/java/com/google/crypto/tink/streamingaead:aes_gcm_hkdf_streaming_key_manager",
    ],
)

java_test(
    name = "AsymmetricTestingServicesTest",
    size = "small",
    srcs = [
        "javatests/com/google/crypto/tink/testing/AsymmetricTestingServicesTest.java",
    ],
    deps = [
        ":testing_api_java_grpc",
        ":testing_api_java_proto",
        ":testing_services",
        "@com_google_protobuf//:protobuf_java",
        "@com_google_protobuf//:protobuf_java_util",
        "@io_grpc_grpc_java//api",
        "@io_grpc_grpc_java//core:inprocess",
        "@io_grpc_grpc_java//protobuf",
        "@io_grpc_grpc_java//stub",
        "@io_grpc_grpc_java//testing",
        "@maven//:com_google_truth_truth",
        "@maven//:junit_junit",
        "@tink_java//proto:tink_java_proto",
        "@tink_java//src/main/java/com/google/crypto/tink/config:tink_config",
        "@tink_java//src/main/java/com/google/crypto/tink/hybrid:ecies_aead_hkdf_private_key_manager",
        "@tink_java//src/main/java/com/google/crypto/tink/internal:key_template_proto_converter",
        "@tink_java//src/main/java/com/google/crypto/tink/signature:ecdsa_sign_key_manager",
    ],
)

java_test(
    name = "JwtServiceImplTest",
    size = "small",
    srcs = [
        "javatests/com/google/crypto/tink/testing/JwtServiceImplTest.java",
    ],
    deps = [
        ":testing_api_java_grpc",
        ":testing_api_java_proto",
        ":testing_services",
        "@com_google_protobuf//:protobuf_java",
        "@com_google_protobuf//:protobuf_java_util",
        "@io_grpc_grpc_java//api",
        "@io_grpc_grpc_java//core:inprocess",
        "@io_grpc_grpc_java//protobuf",
        "@io_grpc_grpc_java//stub",
        "@io_grpc_grpc_java//testing",
        "@maven//:com_google_truth_truth",
        "@maven//:junit_junit",
        "@tink_java//proto:tink_java_proto",
        "@tink_java//src/main/java/com/google/crypto/tink:binary_keyset_reader",
        "@tink_java//src/main/java/com/google/crypto/tink:key_templates",
        "@tink_java//src/main/java/com/google/crypto/tink/internal:key_template_proto_converter",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_hmac_key_manager",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_mac_config",
        "@tink_java//src/main/java/com/google/crypto/tink/jwt:jwt_signature_config",
        "@tink_java//src/main/java/com/google/crypto/tink/signature:ecdsa_sign_key_manager",
    ],
)
